package dao

import (
	"gitee.com/cyanbleeze/go-image-management/internal/model"
	"gitee.com/cyanbleeze/go-image-management/pkg/app"
)

func (d *Dao) CreateCategory(name string, desc string, userID uint) error {
	category := model.Category{
		Name:   name,
		Desc:   desc,
		UserID: userID,
		Type:   2,
	}
	return category.Create(d.engine)
}

func (d *Dao) UpdateCategory(id uint, name string, desc string) error {
	category := model.Category{
		Name: name,
		Desc: desc,
	}
	category.ID = id
	return category.Update(d.engine)
}

func (d *Dao) DeleteCategory(id uint) error {
	category := model.Category{}
	category.ID = id
	return category.Delete(d.engine)
}

func (d *Dao) GetCategory(id uint, userID uint) (model.Category, error) {
	category := model.Category{
		UserID: userID,
	}
	category.ID = id
	return category.Get(d.engine)
}

func (d *Dao) GetCategoryList(userID uint, page int, pageSize int) ([]*model.Category, error) {
	category := model.Category{
		UserID: userID,
	}
	return category.List(d.engine, app.GetPageOffset(page, pageSize), pageSize)
}
